package com.example.back.controller;

import com.example.back.dto.req.DeleteEscortProductDto;
import com.example.back.dto.req.GetEscortProductList;
import com.example.back.dto.req.PutwayEscortProductDto;
import com.example.back.dto.resp.EscortProductList;
import com.example.back.service.EscortProductService;
import com.example.common.entity.EscortProduct;
import com.example.common.support.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName EscortProductController
 * @Author wengjt
 * @Date 2021/5/7 15:14
 * @Description
 **/
@RestController
@RequestMapping("/escortProduct")
@Api(tags = "陪护套餐服务管理")
public class EscortProductController {
    @Resource
    private EscortProductService escortProductService;

    @GetMapping("/escortProductList")
    @ApiOperation(value = "陪护套餐列表查询", notes = "陪护套餐列表查询")
    public Result<EscortProductList> getEscortProductList(GetEscortProductList dto) {
        return Result.success(escortProductService.getEscortProductList(dto));
    }

    @GetMapping("/info")
    @ApiOperation(value = "获取单个详情", notes = "获取单个详情")
    @ApiImplicitParam(name = "cpId", value = "套餐id")
    public Result<EscortProduct> getEscortProduct(Long cpId) {
        return Result.success(escortProductService.getEscortProduct(cpId));
    }

    @PutMapping("/escortProduct")
    @ApiOperation(value = "修改单个陪护套餐", notes = "修改单个陪护套餐")
    public Result<Object> updateEscortProduct(@RequestBody EscortProduct escortProduct) {
        return Result.success(escortProductService.updateEscortProduct(escortProduct));
    }

    @PostMapping("/escortProduct")
    @ApiOperation(value = "新增单个陪护套餐", notes = "新增单个陪护套餐")
    public Result<Object> insertEscortProduct(@RequestBody EscortProduct escortProduct) {
        return Result.success(escortProductService.insertEscortProduct(escortProduct));
    }

    @DeleteMapping("/escortProduct")
    @ApiOperation(value = "删除单个陪护套餐", notes = "删除单个陪护套餐")
    public Result<Object> deleteEscortProduct(DeleteEscortProductDto dto) {
        return Result.success(escortProductService.deleteEscortProduct(dto.getEpId()));
    }

    @PostMapping("/escortProduct/showAble")
    @ApiOperation(value = "上下架", notes = "上下架")
    public Result<Object> updateShowAbleById(PutwayEscortProductDto dto) {
        return Result.success(escortProductService.updateShowAbleById(dto.getEpId(), dto.getShowAble()));
    }
}
